package com.iSnail.ms.gather;

import com.iSnail.ms.gather.db.DBManager;
import com.iSnail.ms.gather.port.Port;
import com.iSnail.ms.util.AppUtil;
import com.iSnail.ms.util.Config;
import com.iSnail.ms.util.Const;
import com.sun.media.Log;

public class AppMain {

	public static void main(String[] args){
		//System.out.println(DBManager.getDirectcon());
		try {
			while(true){
				read();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private static void testPort() throws Exception{
		Port read = new Port(Config.getConfigValue("read_port"));
		read.init();
		read.read();
		
		Port write = new Port(Config.getConfigValue("write_port"));
		write.init();
		write.read();
		read.write(Const.START_COMMAND_TEMPER);
		while(true){
			Thread.sleep(1000);
			write.write(Config.getConfigValue("test_msg"));
		}
	}
	
	private static void writeandread() throws Exception{
		Port write = new Port(Config.getConfigValue("write_port"));
		write.init();
		write.write(Const.START_COMMAND_TEMPER);
		write.close();
		
		Port read = new Port(Config.getConfigValue("read_port"));
		read.init();
		read.read();
		read.close();		
	}
	
	private static void read() throws Exception{
		Port read = new Port(Config.getConfigValue("read_port"));
		read.init();
		read.read();
		while(true){
			read.statusChange();
			Thread.sleep(500);
			if(System.currentTimeMillis()%2==1){
				read.write(Const.START_COMMAND_PRESS);
			}
			//else{
				//read.write(Const.START_COMMAND_TEMPER);
			//}
			Thread.sleep(500);
			//System.out.println("========================================");
		}
	}
}